#include "../Headers/config.h"

#include "mods/mod.h"
#include "mods/an.h"
#include "mods/ws.h"
#include "mods/fs.h"
#include "mods/fs.h"
#include "mods/um.h"
#include "mods/em.h"
#include "mods/settings.h"

#include "gui.window.h"
#include "gui.button.h"
#include "gui.menu.h"
#include "gui.text.h"
#include "gui.browser.h"

using namespace TOB;

void GUI() {
}

int main(int argc, char *argv[]) {
  UIWindow::init();

  Config _config(CONFIG);
  Config _lang(_config["lang"]);
  Config _ws_code(_config["ws-code"]);

  std::string str = CONVERT(_config["server-NS"]);
  Nameserver _ns(str);
  if(!_ns.isConnected()) {
    UIWindow window(0, 0, 0, 0);
    window.putString(_lang["ns-doesnt-respond"]);
    window.putChar('\n');
    window.putString(_lang["any-key"]);
    window.getChar();
    UIWindow::end(); 
    return -1;
  }

  Nameserver::IP nsip;
  Nameserver::convertString(str, nsip);
  UIConfig config = {_config, _lang, _ws_code, _ns, nsip, 15, 0};

  config.offsetX = 18;
  config.offsetY = 0;
  
  UI_AN *an = new UI_AN(config);
  an->run();

  UIMenu *menu = new UIMenu(0, 0, config.offsetX, 0);
  // User management
  menu->insert(config.lang["user-management"], [&](){ 
      UI_UM um(config);
      um.run(); 
    });

  menu->insert(config.lang["e-mail"], [&](){
      UI_EM em(config);
      em.run();
    });

  // File sharing
  menu->insert(config.lang["file-sharing"], [&](){ 
      UI_FS fs(config);
      fs.run(); 
    });

  //menu.insert(config.lang["calendar"], [](){});
  //menu.insert(config.lang["to-do-list"], [](){});
  //menu.insert(config.lang["directory"], [](){});
  //menu.insert(config.lang["time"], [](){});

  // Browser
  menu->insert(config.lang["web-server"], [&](){ 
      UI_WS ws(config);
      ws.run();
    });

  // Settings
  menu->insert(config.lang["settings"], [&](){ 
      UI_Settings settings(config);
      settings.run(); 
    });

  // Exit
  menu->insert(config.lang["quit"], [&](){ menu->running = false; });
  menu->focus();
  an->dispose();

  delete menu;

  UIWindow::end();
  return 0;
}
